package team.group.exam.action;

import java.util.List;

import team.group.exam.biz.ITitlesBiz;
import team.group.exam.entity.TbQuestionbank;

import com.opensymphony.xwork2.ActionSupport;

public class TitlesAction extends ActionSupport{
	private int currentPage;
	private int totalPage;
	private ITitlesBiz titleBiz;
	private TbQuestionbank title;
	private int tid;
	private List<TbQuestionbank> list;
	private String type;
	private List<String> listType;
	
	/**
	 * 列出所有的题目
	 * @return
	 */
	public String getAllTitle(){
		if(currentPage <= 0){
			currentPage = 1;
		}
		if(totalPage <= 0){
			totalPage = 1;
		}
		if(currentPage > totalPage){
			currentPage = totalPage;
		}
		list = titleBiz.getAllTitles(currentPage);
		totalPage = titleBiz.getTotalPage();
		return SUCCESS;
	}
	
	public String queryTitleByType(){
		list = titleBiz.getByType(type);
		return SUCCESS;
	}
	/**
	 * 根据id查询一条题目
	 * @return
	 */
	public String getById(){
		title = titleBiz.getTitleById(tid);
		return SUCCESS;
	}
	/**
	 * 删除一个题目
	 * @return
	 */
	public String delete(){
		System.out.println(tid);
		titleBiz.deleteTitle(titleBiz.getTitleById(tid));
		return SUCCESS;
	}
	
	/**
	 * 修改一条题目信息
	 * @return
	 */
	public String update(){
		title = titleBiz.getTitleById(tid);
		return SUCCESS;
	}
	/**
	 * 增或者修改一条题目记录
	 * @return
	 */
	public String addOrUpdate(){
		if(title.getTitleId() == null){
			titleBiz.addTitle(title);
		}else{
			titleBiz.updateTitle(title);
		}
		return SUCCESS;
	}
	
	public String getAllTitleType(){
		listType = titleBiz.getAllTypes();
		System.out.println("类型值："+listType.size());
		return SUCCESS;
	}
	public String getAllTitleType2(){
		listType = titleBiz.getAllTypes();
		System.out.println("类型值："+listType.size());
		return SUCCESS;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public ITitlesBiz getTitleBiz() {
		return titleBiz;
	}
	public void setTitleBiz(ITitlesBiz titleBiz) {
		this.titleBiz = titleBiz;
	}
	public int getTid() {
		return tid;
	}
	public void setTid(int tid) {
		this.tid = tid;
	}
	public TbQuestionbank getTitle() {
		return title;
	}
	public void setTitle(TbQuestionbank title) {
		this.title = title;
	}
	public List<TbQuestionbank> getList() {
		return list;
	}
	public void setList(List<TbQuestionbank> list) {
		this.list = list;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<String> getListType() {
		return listType;
	}

	public void setListType(List<String> listType) {
		this.listType = listType;
	}
	
}
